package org.zhs.es.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @Author: zhs
 * @Date: 2021/6/24 11:06
 * @Description:
 *
 * 修改文档
 *
 */
public class ESTest_Document_Update {
    public static void main(String[] args) throws IOException {
        //创建ES客户端
        RestHighLevelClient rsClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9200,"http")));


        //修改数据
        UpdateRequest request = new UpdateRequest();
        request.index("user").id("1001");
        request.doc(XContentType.JSON,"sex","男的");

        UpdateResponse response = rsClient.update(request, RequestOptions.DEFAULT);


        //关闭客户端
        rsClient.close();
    }
}
